package org.yenn.pattern.aliyun.j2ee.servicelocator;

import org.junit.Test;

import static org.junit.Assert.*;

/**
 * @Author: yerenyun
 * @Description:步骤 6
 * 使用 ServiceLocator 来演示服务定位器设计模式。
 */
public class ServiceLocatorPatternDemo {

    /**
     * 步骤 7
     * 验证输出。
     *
     * Looking up and creating a new Service1 object
     * Executing Service1
     * Looking up and creating a new Service2 object
     * Executing Service2
     * Returning cached Service1 object
     * Executing Service1
     * Returning cached Service2 object
     * Executing Service2
     */
    @Test
    public void getService() {
        Service service = ServiceLocator.getService("Service1");
        service.execute();
        service = ServiceLocator.getService("Service2");
        service.execute();
        service = ServiceLocator.getService("Service1");
        service.execute();
        service = ServiceLocator.getService("Service2");
        service.execute();
    }
}